﻿using QuanLyBanHang.DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
namespace QuanLyBanHang.DAL
{
   public class KhachHangDAL
    {
        public static KetNoiSQL kn =new KetNoiSQL();
        public static int ThemKhachHang(KhachHangDTO kh)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "insert into KhachHang values (@MaKH,@HoTenKH,@DiaChi,@DienThoai, @LoaiKH)";
            cmd.Parameters.Add("@MaKH", SqlDbType.NVarChar, 50).Value = KhachHangDTO.MaKhachHang;
            cmd.Parameters.Add("@HoTenKH", SqlDbType.NVarChar, 50).Value = KhachHangDTO.HoTen;
            cmd.Parameters.Add("@DiaChi", SqlDbType.NVarChar, 50).Value = KhachHangDTO.DiaChi;
            cmd.Parameters.Add("@DienThoai", SqlDbType.NVarChar,50).Value = KhachHangDTO.DienThoai;
            cmd.Parameters.Add("@LoaiKH", SqlDbType.NVarChar,50).Value = KhachHangDTO.LoaiKhachHang;
            return kn.DongThucThi(cmd);
        }
        public static int XoaKhachHang(KhachHangDTO kh)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "delete KhachHang where MaKH=@MaKH";
            cmd.Parameters.Add("@MaKH", SqlDbType.NVarChar, 50).Value = KhachHangDTO.MaKhachHang;
           
            return kn.DongThucThi(cmd);
        }
        public static int SuaKhachHang(KhachHangDTO kh)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "update KhachHang set HoTenKH=@HoTenKH,DiaChi=@DiaChi,DienThoai=@DienThoai,LoaiKH=@LoaiKH where MaKH=@MaKH ";
            cmd.Parameters.Add("@MaKH", SqlDbType.NVarChar, 50).Value = KhachHangDTO.MaKhachHang;
            cmd.Parameters.Add("@HoTenKH", SqlDbType.NVarChar, 50).Value = KhachHangDTO.HoTen;
            cmd.Parameters.Add("@DiaChi", SqlDbType.NVarChar, 50).Value = KhachHangDTO.DiaChi;
            cmd.Parameters.Add("@DienThoai", SqlDbType.NVarChar,50).Value = KhachHangDTO.DienThoai;
            cmd.Parameters.Add("@LoaiKH", SqlDbType.NVarChar, 50).Value = KhachHangDTO.LoaiKhachHang;
            return kn.DongThucThi(cmd);
        }
        public static DataTable LayTatCaThongTinKhachHang(KhachHangDTO kh)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "select * from KhachHang";

            return kn.LayDuLieu(cmd);

        }
       //load du lieu len dataGRIDVIEW input la dieu kien
        //KhachHang " khoang cach de nhan cau dieu kien
        public static DataTable HienThiThongTinDieuKien(string dieukien)
        {
            return KetNoiSQL.LayDuLieuSelect("select * from KhachHang " + dieukien);
        }
        //lay sdt ua khach hang
        

    }
}
